'use strict';

const Controller = require('egg').Controller;

class TopicController extends Controller {
  async topicList() {
    const { ctx, logger } = this
    const { uid, departureTime, topicType, cityType, limit, offset } = ctx.request.body
    
    logger.info("/topic/topicList 入参======>>" + JSON.stringify(ctx.request.body))

    ctx.body = await ctx.service.topic.selectTopics(
      false,
      uid,
      departureTime, 
      topicType, 
      cityType,
      limit, 
      offset
    )

    logger.info("/topic/topicList 出参======>>" + JSON.stringify(ctx.body))
  }

  async postTopic() {
    
    const { ctx, logger } = this
    const { 
      uid,
      departureTime, 
      topicType, 
      cityType,
      peopleNum,
      remark,
      linkman,
      linkPhone } = ctx.request.body
    
    logger.info("/topic/postTopic 入参======>>" + JSON.stringify(ctx.request.body))

    ctx.body = await ctx.service.topic.addTopic(
      uid,
      departureTime, 
      topicType, 
      cityType,
      peopleNum,
      remark,
      linkman,
      linkPhone
    )

    logger.info("/topic/postTopic 出参======>>" + JSON.stringify(ctx.body))
  }

  async myTopics() {
    const { ctx, logger } = this
    const { uid, departureTime, topicType, cityType, limit, offset } = ctx.request.body
    
    logger.info("/topic/topicList 入参======>>" + JSON.stringify(ctx.request.body))

    ctx.body = await ctx.service.topic.selectTopics(
      true,
      uid, 
      departureTime,
      topicType, 
      cityType,
      limit, 
      offset
    )

    logger.info("/topic/topicList 出参======>>" + JSON.stringify(ctx.body))
  }
}

module.exports = TopicController;
